package com.gitee.ywj1352.算法.回溯;

public class 颜色渲染 {
    /**
     1 1 1      2 2 2
     1 1 0  ==> 2 2 0
     1 0 1      2 0 1
     */
    public static int[][] floodFill(int[][] image, int sr, int sc, int newColor) {
        dfs(image, sr , sc, newColor);
        return image;

    }
    public static void dfs(int[][] image, int sr, int sc, int newColor){
        if(sr < 0 || sc < 0 || sr >= image.length || sc >= image[0].length || image[sr][sc] == 0 ){
            System.out.println(String.format("%s : %s ", sr , sc));
            return;
        }
        image [sr][sc] = newColor;
        dfs(image, sr + 1, sc , newColor);
        dfs(image, sr , sc + 1, newColor);
        dfs(image, sr - 1, sc , newColor);
        dfs(image, sr , sc - 1, newColor);
    }


    public static void main(String[] args) {

        int [][] arr = new int[3][3];
        arr[0] = new int[]{1,1,1};
        arr[1] = new int[]{1,1,0};
        arr[2] = new int[]{1,0,1};

        floodFill(arr, 1, 1, 2);





    }
}
